<template>
  <div>
    {{ workdata }}
    <p v-for="i in workdata" :key="i">
      <van-field
        v-if="i.type == 'input'"
        :label="i.lable"
        v-model="values[i.lable]"
      />
      <select v-if="i.type == 'select'" v-model="values[i.lable]">
        <option :value="j.type" v-for="j in i.values" :key="j">
          {{ j.name }}
        </option>
      </select>
      <van-uploader v-if="i.type == 'file'" v-model="values[i.lable]" />

      <el-date-picker
        v-if="i.type == 'datetime'"
        type="date"
        placeholder="选择日期"
        value-format="YYYY-MM-DD"
        v-model="values[i.lable]"
      >
      </el-date-picker>
    </p>
    <div v-show="show">
      <van-checkbox-group v-model="ids">
        <van-checkbox :name="i.id" v-for="i in postlist" :key="i">
          {{ i.name }}
        </van-checkbox>
      </van-checkbox-group>
      
    </div>
    审批人:
    <button @click="add">+</button><br>
    <button @click="submit">添加</button>
  </div>
</template>

<script>
import axios from "../../http/axios";
export default {
  data() {
    return {
      workid: this.$route.query.id,
      workdata: [],
      values: {},
      show:false,
      postlist:[],
      ids:[],
      name:''
    };
  },
  methods: {
    getdata() {
      axios("/work?workid=" + this.workid, "get").then((res) => {
        this.workdata = JSON.parse(res.list.params);
        this.name=res.list.name
        console.log(res)
        console.log(this.name)
      });
    },
    add() {
      this.show=true
      
      axios("/posts",'get').then(res => {
        console.log(res);
        this.postlist = res.list;
        // this.getroles()
      });
    },
    submit(){
      console.log(this.values)
      axios('/addtask','post',{'params':JSON.stringify(this.values),'name':this.name,'ids':this.ids}).then(res=>{
        console.log(res)
      })
    }
    // close(){
    //   this.show=false
    // }
  },
  mounted() {
    this.getdata();
  },
};
</script>

<style>
</style>